<?php

// *** Documentation
/*______________________________________________________________________________

  Generic Page Frame for PHP Scripts

  Last Update: Mar 2007
  Author: Tom at klenwell@gmail.com

  SUMMARY
    summary here
    
  NOTES
    This framework provides the core functionality (buffering, session, etc.) for
    a dynamic XHTML webpage.  However, it ignores some security precautions for the
    sake of ease in usage.  For production sites, a more secure framework is
    recommended.
    
______________________________________________________________________________*/


// *** Pre-Script (constants, session, imports)
/*____________________________________________________________________________*/

// ** Constants / Script Globals
  
    // timer
    $_tx1 = microtime();
    
    // syntax declarations
    define('PAGE_ID', 'demo');
    define('INC_KEY', PAGE_ID . 'KEY');
    define('DS', DIRECTORY_SEPARATOR);


// ** Session / Buffer    

    if ( ob_get_level() == 0 ) ob_start();
    session_start();
  

// ** Path Settings / Imports

    // Page ID (used as DOM id for template page tags below)
    $_PAGE['id'] = 'demo';
    
    // Dir Settings
    $_DIR['super'] = dirname($_SERVER['DOCUMENT_ROOT']) . DS;
    $_DIR['root'] = dirname($_SERVER['PHP_SELF']) . DS;
    $_DIR['code'] = $_DIR['super'] . 'php' . DS;

    // Imports
    #require_once($_DIR['code'] . 'fname.php');

  
/*============================================================================*/



// *** Data (triggers, flags, HTML, and other variables)
/*____________________________________________________________________________*/

// ** Controller Flags

  // Triggers (Page Events)
  $_TRIGGER['event'] = 0;
  
  // Show
  $_SHOW['block'] = 0;


// ** Data

    // Google Analytics Code
    $GA_CODE = '';

    // Head
    $_DATA['head_title'] = 'Klenwell Scriptframe v1.1';
    $_DATA['charset'] = 'ISO-8859-1';
  

// ** Output

  // CSS Settings
  $_CSS['local'] = <<<CSS
/* initialize */
h1, h2, h3, h4, h5, h6 { margin:0 0 .5em; padding:0; }
p, pre, blockquote, ul, ol, dl, address { margin: .5em 0; padding: 0; }
ul li { list-style:none; margin-left:.5em; }
form, fieldset { margin: 0; padding: 0; }
dd, blockquote { margin-left: .5em; }
form label { cursor: pointer; }
img, fieldset { border: none; }
input, select, textarea { font-size: 100%; }
table { border-collapse:collapse; }
td { vertical-align:top; }
.left { float:left; }
.right { float:right; }
.clear { clear:both; }

/* page centering */
html, body, #page_id, #page_table { height:100%; margin:0; }
table#page_table { width:100%; }
#page_table td { padding:0px; }
td#page_table_main { vertical-align:middle; width:100%; padding-bottom:40px; }
#core_panel { width:100%; }

/* splash settings */
body { color:#666; background-color:#000; }
#page_id { background-color:transparent; }
#page_table { background-color:transparent; }
#page_table_main { background-color:transparent; }
#core_panel_center { background-color:transparent; text-align:center; }
#upper_splash { padding:40px; background-color:#111; }
#lower_splash { padding:20px; background-color:#222; } 
#anklebar { padding:20px 40px; background-color:#333; }

#footer_panel { padding:4px; }
.copyright { margin:0 150px; }
CSS;
  

/*============================================================================*/



// *** Controllers (handles requests and sets event triggers)
/*____________________________________________________________________________*/

// ** Default

// ** GET-triggered Requests
if ( $_GET['trigger'] ) $_TRIGGER['event'] = 1;

// ** POST-triggered Requests
if ( $_POST['VAR'] ) $_TRIGGER['VAR'] = 1;

// ** COOKIE-triggered Requests

/*============================================================================*/



// *** Events (trigger-controlled events)
/*____________________________________________________________________________*/

// Generic Event
if ( $_TRIGGER['event'] )
{
  $_HTML['event'] = 'event output here at line ' . __LINE__;
}

/*============================================================================*/


// *** Output (handles requests and sets event triggers)
/*____________________________________________________________________________*/

// ** Heredoc Blocks

// Head (core)
  $_HTML['head'] = <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>{$_DATA['head_title']}</title>

<!-- META TAGS -->
<meta name="keywords" content="keywords, go, here" />
<meta name="description" content="a descripton of the page" />
<meta http-equiv="Content-Type" content="text/html; charset={$_DATA['charset']}" />
<!-- <meta http-equiv="refresh" content="600" /> -->
<!-- <meta http-equiv="refresh" content="3;url=URL" /> -->

<!-- LINKS: css, javascript, favicon -->
<!-- <link rel="stylesheet" type="text/css" href="http://klenwell.googlecode.com/svn/trunk/templates/html_css/basic.css" /> -->
<!-- <script src="http://klenwell.googlecode.com/svn/trunk/JS/os_library/prototype.lite.js" type="text/javascript"></script> -->
<!-- <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> -->

<!-- CSS -->
<style type="text/css">
{$_CSS['local']}
</style>

<!-- JAVASCRIPT -->
<script type="text/javascript">
</script>

</head>
HTML;

    // Body
    $_HTML['body'] = <<<HTML
<body>
<div class="page" id="page_id">
    
<table id="page_table"><tr>

<td id="page_table_main">

<!-- CORE -->
<table id="core_panel"><tr>
<td id="core_panel_center">
<div id="upper_splash">upper_splash</div>
<div id="lower_splash">lower_splash</div>
<div id="anklebar">anklebar</div>

<div id="footer_panel">
<div id="footer_left" class="left"><a href="http://jigsaw.w3.org/css-validator/">
<img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" />
</a></div>
<div id="footer_right" class="right"><a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Strict" height="31" width="88" />
</a></div>
<div class="copyright">some rights reserved, &#169; 2007</div>
</div>

</td>
</tr></table>
<!-- end CORE -->

</td>

</tr></table>
</div>    
HTML;


  // Footer
  $_HTML['foot'] = <<<HTML

<!-- Google Analytics -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("$GA_CODE");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</body>
</html>
HTML;


// ** Print

  echo $_HTML['head'];
  echo $_HTML['body'];
  echo $_HTML['foot'];

/*============================================================================*/



// *** Post-Script (close HTML, flush buffer, and other backend operations)
/*____________________________________________________________________________*/

// ** Flush Buffer
while (ob_get_level() > 0) { ob_end_flush(); }
flush();
echo "<!-- buffer flushed at " . date('r') . " -->";

// ** Page Timer
$_tx2 = microtime();
$_tx3 = number_format(((substr($_tx2,0,9)) + (substr($_tx2,-10)) - (substr($_tx1,0,9)) - (substr($_tx1,-10))),4); 
echo "\n<!-- script [id: {$_PAGE['id']}] generated in $_tx3 s -->";

/*============================================================================*/
// * That's All Folks!
?>
